﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace KLADR
{
    public partial class KLADREdit : UserControl , INotifyPropertyChanged
    {
        private KLADR kladr_object;

        public KLADREdit()
        {
            InitializeComponent();
            kladr_object = new KLADR();
        }

        public string SqlConnectionString
        { 
            get
            { 
                return kladr_object.SqlConnectionString;
            } 
            set
            {
                if (string.IsNullOrEmpty(value)) return; kladr_object.SqlConnectionString = value; 
            } 
        }

        public string DefaultKladr { set { if (null != value) kladr_object.DefaultKladr = value; } }

        [Bindable(true)]
        public string Address
        {
            get
            {
                return kladr_object.Address;
            }
            set
            {
                if (kladr_object.Address != value)
                {
                    kladr_object.Address = value;
                    textBoxAddress.Text = kladr_object.ToString();
                    NotifyPropertyChanged("Address");
                }
            }
        }

        private void buttonEdit_Click(object sender, EventArgs e)
        {
            string old = kladr_object.Address;
            kladr_object.InteractiveEdit();
            textBoxAddress.Text = kladr_object.ToString();
            if (kladr_object.Address != old)
                NotifyPropertyChanged("Address");
        }

        private void KLADREdit_Load(object sender, EventArgs e)
        {
            DefaultKladr = Properties.Settings.Default.kladrDefault;
        }


        public event PropertyChangedEventHandler PropertyChanged;

        private void NotifyPropertyChanged(String info)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(info));
            }
        }



    }
}
